package com.sikaryofficial.workbench.config.handler;

import com.sikaryofficial.common.core.constant.GenCodeTypeEnum;
import com.sikaryofficial.workbench.config.handler.impl.DefaultCodeStrategy;
import com.sikaryofficial.workbench.config.handler.impl.OrderCodeStrategy;
import com.sikaryofficial.workbench.config.handler.impl.OrderItemCodeStrategy;
import org.apache.ibatis.reflection.MetaObject;


/**
 * @author : wuweihong
 * @desc : TODO  请填写你的功能描述
 * @date : 2024-09-30
 */

public class BusinessCodeContext {

    private BusinessCodeStrategy businessCodeStrategy;

    public BusinessCodeContext(BusinessCodeStrategy businessCodeStrategy) {
        this.businessCodeStrategy = businessCodeStrategy;
    }

    public String executeStrategy(MetaObject metaObject) {
        return businessCodeStrategy.generateCode(metaObject);
    }

    public static BusinessCodeContext createContextByCodeType(GenCodeTypeEnum genCodeTypeEnum) {
        BusinessCodeContext businessCodeContext;
        switch (genCodeTypeEnum) {
            case ORDER:
                businessCodeContext = new BusinessCodeContext(new OrderCodeStrategy());
                break;
            case ORDER_ITEM:
                businessCodeContext = new BusinessCodeContext(new OrderItemCodeStrategy());
                break;
            default:
                businessCodeContext = new BusinessCodeContext(new DefaultCodeStrategy());

        }
        return businessCodeContext;
    }

}
